package com.hongye.manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hongye.common.entity.InformationEntity;
import com.hongye.manager.mapper.InformationMapper;
import com.hongye.manager.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InformationServiceImpl extends ServiceImpl<InformationMapper, InformationEntity> implements InformationService {

    @Autowired
    private InformationMapper informationMapper;

    @Override
    public List<InformationEntity> selectUserPage(Page<InformationEntity> page, String name) {

        QueryWrapper<InformationEntity> qw = new QueryWrapper<>();
        qw.like("information_title",name);

        IPage<InformationEntity> page1 = informationMapper.selectPage(page, qw);
        List<InformationEntity> records = page1.getRecords();
        return records;
    }

    @Override
    public boolean isExist(InformationEntity informationEntity) {
        QueryWrapper<InformationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("information_title",informationEntity.getInformationTitle());

        if (informationEntity.getId() != null){
            wrapper.ne("id",informationEntity.getId());
        }

        return count(wrapper) > 0;
    }

}
